<?php
namespace View;

class NavigationView {

	public static function getEditUserLink($userId) {
		return self::getpostLink($userId) . "&edit";
	}

	private static $postID = "postID";
	private static $edit = "&edit";
	/**
	 * @return boolean
	 */
	public static function isViewingpost() {

		if (isset($_GET[self::$postID])) {
			return true;
		} else {
			return false;
		}
	}

	public static function isTryingToEdit() {

		if (isset($_GET[self::$postID. self::$edit])) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * return String URL
	 */
	public static function getpostListLink() {
		return "?";
	}

	public static function getpostLink(\Model\post $post) {
		return "?" . self::$postID . "=" . $post -> getId();
	}

	/**
	 * @return \Model\post selected post
	 */
	public static function getSelectedpost(\Model\PostHandler $posthandler, \Model\Database $database) {
		if (isset($_GET[self::$postID])) {
			$urlId = $_GET[self::$postID];

			if ($urlId != "0" && intval($urlId) == 0) {
				throw new \Exception("getSelectedpost() URL called with wrong format");
			} else {
				$postID = intval($urlId);
				return $posthandler -> getPostByID($postID, $database);
			}
		} else {
			throw new \Exception("getSelectedpost can only be called when we view a post");
		}
	}

}
